package com.jf3q.iot.config;

import com.jf3q.iot.job.ElectricityMeterJob;
import org.quartz.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class JobConfig {

    /**
     * 定时任务1：
     * 同步用户信息Job（任务详情）
     */
    @Bean
    public JobDetail electricityJobDetail(){

        JobDetail JobDetail = JobBuilder.newJob(ElectricityMeterJob.class)
                .storeDurably() //必须调用该方法，添加任务
                .build();

        return JobDetail;
    }

    @Bean
    public Trigger testTrigger(){

        //corn  从数据库查出
        CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder.cronSchedule("0 0 0/2 * * ?"); //配置任务频率

        Trigger trigger = TriggerBuilder.newTrigger()
                .forJob(electricityJobDetail())
                .withSchedule(cronScheduleBuilder) //对触发器配置任务
                .build();

        return trigger;
    }



}
